#pragma once
#include <iostream>
#include <mysql/mysql.h>

class MysqlConn
{
public:
    MysqlConn();
    ~MysqlConn();
    bool connect(const char *user, const char *password, const char *dbname, const char *ip, const unsigned short &port = 3306);
    bool update(const char *sql);
    bool query(const char *sql);
    bool next();
    std::string value(const unsigned int &index);
    const char *getError();
    // 事务操作
    bool transaction();
    // 提交事务
    bool commit();
    // 事务回滚
    bool rollBack();

private:
    void freeRes();
    MYSQL *m_conn = nullptr;
    MYSQL_RES *m_res = nullptr;
    MYSQL_ROW m_row = nullptr;
};
